﻿using System;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using ModernHttpClient;
using Newtonsoft.Json;
using SpotOffer.Constants;
using SpotOffer.DataModels;
using SpotOffer.Models;
using SpotOffer.Services;
using SpotOffer.Services.HttpClient;
using Xamarin.Forms;

[assembly: Dependency(typeof(CityCategoryService))]
namespace SpotOffer.Services
{
    public class CityCategoryService : ICityCategoryService
    {
        public CityCategory CitiesCat { get; set; }


        public async Task<CityCategory> GetCitiesCategories()
        {
            HttpResponseMessage res =
                await RestClient.GetClient().GetAsync(ServiceConstants.CityEndpoint);
            res.EnsureSuccessStatusCode();
            string json = await res.Content.ReadAsStringAsync();
            CitiesCat = ((CityCategory)JsonConvert.DeserializeObject(json, typeof(CityCategory)));
            return CitiesCat;
        }
    }
}